//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    imgurl: app.urlimg,
    cateData: [],
    cateItem: [],
    selectarrIndex: '0',
  },
  onLoad: function (o) {
    var that = this;
    wx.request({
      url: app.url + 'api_goods/category_list',
      data: {
      },
      header: {
        'content-type': 'application/json',
        'token': wx.getStorageSync('token_key')
      }, success: function (json) {
        if (json.data.done == true) {
          console.log(json.data.result)
          that.setData({cateData: json.data.result, cateItem: json.data.result[0].child,})
        } else {
          app.apperror(json);
        }
      }
    })


    wx.getSystemInfo({
      success: function (res) {
        var h = res.screenHeight - 120;
        console.log(h);
        h = h + 'px';
        that.setData({ screenHeight: h })
      },
    })

  },

  autoFormId: function (e) {
    wx.request({
      url: app.url + "api_team/collectFormId",
      data: {
        formId: e.detail.formId
      },
      header: {
        'content-type': 'application/json',
        'token': wx.getStorageSync('token_key')
      },
      success: function (result) { }
    });
  },


  l_home: function (e) {
    wx.reLaunch({
      url: '/pages/tabBar/index/index',
    })
  },
  // 
  l_cate: function (e) {
    wx.reLaunch({
      url: '/pages/category/index'
    })
  },

  l_cart: function (e) {
    wx.reLaunch({
      url: '/pages/shop/index'
    })
  },
  l_account: function (e) {
    wx.reLaunch({
      url: '/pages/tabBar/account/index'
    })
  },


  // 响应选中分类
  selectCategory: function (e) {
    var that = this;
    var cid = e.currentTarget.id;
    that.setData({
      cateItem: that.data.cateData[cid].child,
      selectarrIndex: cid
    })
  }, categoryTAP: function (e) {
    var fid = e.currentTarget.id;
    var name = e.currentTarget.dataset.name;
    wx.navigateTo({
      url: '/pages/goods/index?category_id=' + fid + '&name=' + name,
    })
  },
  //分享
  onShareAppMessage: function () {

  },
})

